angular.module('activities.modal_services', [])

.factory 'Toast', ()->
  Toast = {}

  Toast.show = (msg)->
    Zepto.toast msg

  return Toast


.factory "SendMessage", ()->
  SendMessage = {}

  SendMessage.send_to_app = (type, data=null)->
    window.parent.postMessage(type, '*')

  SendMessage

.factory "VcodeService", ($rootScope, $timeout)->
  {
    stop_reject_flag: false

    stopReject: (usage)->
      this.stop_reject_flag = true
      this.setRejectWaitingHandler(usage, 0)

    setRejectWaiting: (usage, sec = 60)->
      this.setRejectWaitingHandler(usage, sec)
      this.rejectWaitingHandler(usage, sec)

    setRejectWaitingHandler: (usage, sec)->
      json_waiting = angular.fromJson window.localStorage.getItem('rt-vcode_reject_waiting')
      json_waiting ||= {}
      json_waiting[usage] = sec
      window.localStorage.setItem('rt-vcode_reject_waiting', angular.toJson(json_waiting))
      $rootScope.vcode_reject_waiting ||= {}
      $rootScope.vcode_reject_waiting[usage] = sec

    startRejectWaiting: (usage)->
      json_waiting = angular.fromJson window.localStorage.getItem('rt-vcode_reject_waiting')
      if json_waiting
        waiting = json_waiting[usage]
        this.rejectWaitingHandler(waiting) if waiting

    startAllRejectWaiting: ()->
      $rootScope.vcode_reject_waiting ||= {}
      json_waiting = angular.fromJson window.localStorage.getItem('rt-vcode_reject_waiting')
      if json_waiting
        for usage, sec of json_waiting
          this.rejectWaitingHandler(usage, sec)

    rejectWaitingHandler: (usage, sec)->
      this.stop_reject_flag = false
      console.log "start vcode reject waiting: #{usage} #{sec}"
      $rootScope.vcode_reject_waiting ||= {}
      $rootScope.vcode_reject_waiting[usage] = sec
      vcode_service = this
      if sec > 0
        for i in [1..sec]
          t = 1000 * i
          past = 1
          $timeout ->
            return if vcode_service.stop_reject_flag
            s = sec - past
            if s >= 0
              vcode_service.setRejectWaitingHandler(usage, s)
              console.debug "vcode reject waiting: #{usage} #{s}"
            past += 1
          , t
      return
  }

.factory "ProvinceCity", ()->
  data = {}
  # data['澳门']=['澳门']
  data['安徽']=["合肥", "芜湖", "蚌埠", "淮南", "马鞍山", "淮北", "铜陵", "安庆", "黄山", "阜阳", "宿州", "滁州", "六安", "宣城", "池州", "亳州"]
  data['北京']=["北京"]
  data['重庆']=["重庆"]
  data['福建']=["福州", "厦门", "漳州", "泉州", "三明", "莆田", "南平", "龙岩", "宁德", "平潭"]
  data['甘肃']=["兰州", "嘉峪关", "金昌", "白银", "天水", "酒泉", "张掖", "武威", "定西", "陇南", "平凉", "庆阳", "临夏", "甘南"]
  data['广东']=["广州", "深圳", "珠海", "汕头", "佛山　　", "韶关", "湛江", "肇庆", "江门", "茂名", "惠州", "梅州", "汕尾", "河源", "阳江", "清远", "东莞", "中山", "潮州", "揭阳", "云浮"]
  data['广西']=["南宁", "柳州", "桂林", "梧州", "北海", "防城港", "钦州", "贵港", "玉林", "百色", "贺州", "河池", "来宾", "崇左"]
  data['贵州']=["贵阳", "六盘水", "遵义", "安顺", "毕节", "铜仁", "黔西", "黔东", "黔南"]
  data['海南']=["海口", "三亚", "儋州", "三沙"]
  data['黑龙江']=["哈尔滨", "齐齐哈尔", "大庆", "鸡西", "鹤岗", "双鸭山", "伊春", "牡丹江", "佳木斯", "七台河", "黑河", "绥化"]
  data['河北']=["石家庄", "唐山", "秦皇岛", "邯郸", "邢台", "保定", "张家口", "承德", "沧州", "廊坊", "衡水"]
  data['河南']=["郑州", "开封", "洛阳", "平顶山", "安阳", "鹤壁", "新乡", "焦作", "濮阳", "许昌", "漯河", "三门峡", "南阳", "商丘", "信阳", "周口", "驻马店"]
  data['湖北']=["武汉", "黄石", "十堰", "宜昌", "襄阳", "鄂州", "荆门", "孝感", "荆州", "黄冈", "咸宁", "随州"]
  data['湖南']=["长沙", "株洲", "湘潭", "衡阳", "邵阳", "岳阳", "常德", "张家界", "益阳", "郴州", "永州", "怀化", "娄底"]
  data['吉林']=["长春", "吉林", "四平", "辽源", "通化", "白山", "松原", "白城"]
  data['江苏']=["南京", "无锡", "徐州", "常州", "苏州", "南通", "连云港", "淮安", "盐城", "扬州", "镇江", "泰州", "宿迁"]
  data['江西']=["南昌", "景德镇", "萍乡", "九江", "新余", "鹰潭", "赣州", "吉安", "宜春", "抚州", "上饶"]
  data['辽宁']=["沈阳", "大连", "鞍山", "抚顺", "本溪", "丹东", "锦州", "营口", "阜新", "辽阳", "盘锦", "铁岭", "朝阳", "葫芦岛"]
  data['内蒙古']=["呼和浩特", "包头", "乌海", "赤峰", "通辽", "鄂尔多斯", "呼伦贝尔", "巴彦淖尔", "乌兰察布"]
  data['宁夏']=["银川", "石嘴山", "吴忠", "固原", "中卫"]
  data['青海']=["西宁", "海东"]
  data['山东']=["济南", "青岛", "淄博", "枣庄", "东营", "烟台", "潍坊", "济宁", "泰安", "威海", "日照", "莱芜", "临沂", "德州", "聊城", "滨州", "菏泽"]
  data['山西']=["太原", "大同", "阳泉", "长治", "晋城", "朔州", "晋中", "运城", "忻州", "临汾", "吕梁"]
  data['陕西']=["西安", "铜川", "宝鸡", "咸阳", "渭南", "汉中", "延安", "榆林", "安康", "商洛"]
  data['上海']=["上海"]
  data['四川']=["成都", "自贡", "攀枝花", "泸州", "德阳", "绵阳", "广元", "遂宁", "内江", "乐山", "南充", "宜宾", "广安", "达州", "眉山", "雅安", "巴中", "资阳"]
  # data['台湾']=
  data['天津']=["天津"]
  data['西藏']=["拉萨", "日喀则", "昌都", "林芝"]
  data['新疆']=["乌鲁木齐", "克拉玛依", "吐鲁番"]
  # data['香港']=
  data['云南']=["昆明", "曲靖", "玉溪", "保山", "昭通", "丽江", "普洱", "临沧"]
  data['浙江']=["杭州", "宁波", "温州", "嘉兴", "湖州", "绍兴", "金华", "衢州", "舟山", "台州", "丽水"]

  obj = {}
  obj.data = data

  obj.getProvinces = () ->
    r = []
    for dtkey in Object.keys(data)
      r.push {id: dtkey, title: dtkey}
    return r

  obj.getCities = (province) ->
    r = []
    for dtkey in data[province]
      r.push {id: dtkey, title: dtkey}
    return r

  return obj

.factory 'AccumulatePoints', ()->
  obj = {}

  data = [
    {title: '日本Narisup娜丽丝防晒喷雾90g', point_cost: 200},
    {title: '娥佩兰薏仁水500ml爽肤水化妆水保湿水补水喷雾', point_cost: 200},
    {title: '香港曼秀雷敦男士草本控油洁面乳 暗疮肌肤男士洗面奶150ml', point_cost: 200},
    {title: '化妆刷套装全套刷粉底刷蜜粉腮红刷眼影刷唇刷高光侧影刷 送刷包', point_cost: 200},
    {title: '西班牙byphasse蓓昂斯四效合一卸妆水深层清洁500ml', point_cost: 200},
    {title: '乐高积木LEGO经典创意箱 10695儿童拼装益智玩具', point_cost: 500},
    {title: '皮尔卡丹纯棉四件套全棉套件1.5米1.8m床上用品三件套床单人被套', point_cost: 500},
    {title: '雅漾 舒护活泉喷雾300ml 大喷套装 补水保湿定妆 舒缓修护 爽肤水', point_cost: 500},
    {title: '美宝莲 超然无瑕轻垫霜黑金气垫bb霜 巨遮瑕轻薄裸妆滋润保湿隔离', point_cost: 500},
    {title: '美宝莲 超然无瑕轻垫霜黑金气垫bb霜 巨遮瑕轻薄裸妆滋润保湿隔离', point_cost: 500},
    {title: '宝宝测温仪婴儿耳温枪儿童智能红外线体温计人体家用温度计高精度', point_cost: 800},
    {title: '卡诗双重功能无硅油洗发水清爽控油头皮去油进口', point_cost: 800},
    {title: 'Travel Friends Ito伊藤拉杆箱女旅行箱行李箱男万向轮20寸登机箱', point_cost: 800},
    {title: '韩伟818燕窝壶加厚玻璃养生壶电煎药壶花茶壶隔水炖盅保温调奶机', point_cost: 800},
    {title: 'Midea/美的 MB-WRD5031A电饭煲5L智能家用多功能4-6-8人家用', point_cost: 800},
    {title: 'LAMY 凌美 LAMY | STAR WARS星球大战合作限量版', point_cost: 1200},
    {title: 'Tom Ford汤姆福特黑金口红TF黑管唇膏9/10/16/44一抹丰盈饱满3g', point_cost: 1200},
    {title: 'HR/赫莲娜蟒纹睫毛膏 防水 浓密扩眼 卷翘睫毛 打造性感迷人电眼', point_cost: 1200},
    {title: '2017新款 爱马仕/Hermes 蓝色橘彩星光香水50ml', point_cost: 1800},
    {title: 'Givenchy/纪梵希轻盈无痕明星四色散粉 定妆控油遮瑕4色可选', point_cost: 1800},
    {title: 'innokids汽车用儿童安全座椅0-4-6-12岁婴儿宝宝新生儿可躺isofix', point_cost: 1800},
    {title: 'SK-II sk2前男友skii护肤面膜pitera精华面膜贴密集修护紧致肌肤', point_cost: 2500},
    {title: '施华洛世奇 swan 经典天鹅链坠白金色锁骨链项链', point_cost: 2500},
    {title: '雪花秀滋阴水乳礼盒套装', point_cost: 2500},
    {title: 'Tiffany/蒂芙尼 蓝心珐琅珠式手链 S925银', point_cost: 3500},
    {title: '肌肤之钥CPB套装水磨精华爽肤水保湿露洁面膏洗面奶补水保湿', point_cost: 3500},
    {title: 'FOREO LUNA mini2 露娜家用电动充电式毛孔清洁美容洗脸刷洁面仪', point_cost: 3500},
    {title: 'FURLA/芙拉链条包 Metropolis系列小方包 单肩斜挎女包', point_cost: 5000},
    {title: 'ReFa CARAT 黎珐 双球滚轮经典款美容仪瘦脸仪', point_cost: 5000},
    {title: 'Prada普拉达 大框太阳眼镜 简洁百搭中性款太阳镜', point_cost: 5000},
    {title: '周生生黄金足金Charme串珠(福禄平安)组合转运珠', point_cost: 6500},
    {title: 'Dyson戴森 V6 car+boat手持除螨吸尘器车用吸尘器', point_cost: 6500},
    {title: 'Zbird/钻石小鸟-18K金钻石挂坠-简单爱情-吊坠项坠挂件钻坠不含链（共约11分，主钻4.5分）', point_cost: 6500},
    {title: 'COACH/蔻驰圆盘带钻小表盘手表女表', point_cost: 8000},
    {title: 'BeatsBeats Solo3 Wireless头戴式无线蓝牙耳机', point_cost: 8000},
    {title: '狠货！科莱丽Clarisonic小S同款美容仪', point_cost: 8000},
    {title: 'miu miu/缪缪女士短款钱包 ', point_cost: 9000},
    {title: 'Dyson/戴森 吹风机 Supersonic HD01', point_cost: 9000},
    {title: '儿童电动车四轮玩具遥控汽车可坐大人宝宝女双驱超大号双人童车男', point_cost: 9000},
    {title: 'LA MER海蓝之谜 活颜焕采修护套装 面部护理套装', point_cost: 10000},
    {title: 'COACH男士皮带双头替换装组合', point_cost: 10000},
    {title: 'HairMax9红光离子美发生发梳子按摩防脱发', point_cost: 10000},
    {title: 'Dior迪奥2016新款女士首饰时尚字母耳环E0533LADMT D300', point_cost: 15000},
    {title: ' 宝格丽BVLGARI慈善款黑陶瓷小红人项链', point_cost: 15000},
    {title: '2017新款Versace/范思哲铆钉黑色男士手包', point_cost: 15000},
    {title: 'Casio/卡西欧 EX-TR750 Van Gogh 自拍神器 ', point_cost: 20000},
    {title: '宝缇嘉/Bottega Veneta钱包男16新款长款拉链钱夹', point_cost: 20000},
    {title: ' 浪琴Longines康卡斯系列手表男表机械表 L3.641.4.56.6', point_cost: 20000},
    {title: 'chanel 斜挎 链条小包', point_cost: 25000},
    {title: 'Chloe蔻依Nile Bracelet杨幂明星同款圆环手提女包', point_cost: 25000},
    {title: '爱马仕QUIZZ系列牛奶白珐琅H扣腰带男款皮带', point_cost: 25000},
    {title: 'Louis Vuitton路易威登lv女包16老花纹SPEEDY30 25手提挎包', point_cost: 30000},
    {title: '香奈儿大双C荔枝牛皮长款钱包', point_cost: 30000},
    {title: 'Gucci/古奇新款女士印花酒神包链条女包（小号）', point_cost: 30000},
  ]

  obj.all = data

  return obj
